﻿using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

[DisallowMultipleComponent]
public class UToggleBtn : ToggleBtn
{
    EventListener eventListener;
    public Text tabNameTxt;

    protected override void Awake()
    {
        base.Awake();
        eventListener = gameObject.AddMissingComponent<EventListener>();
        if (eventListener) { eventListener.onPointerClick += OnPointerClick; }
    }

    void OnDestroy()
    {
        if (eventListener) { eventListener.onPointerClick -= OnPointerClick; }
    }

    void OnPointerClick(GameObject go, PointerEventData eventData) { OnClick(); }

    public override void SetTabName(string name)
    {
        if (tabNameTxt) { tabNameTxt.text = name; }
    }

    public override void SetTabState(bool enabled)
    {
        var graphic = GetComponent<Graphic>();
        if (graphic) { graphic.raycastTarget = enabled; }
    }
}